WD=$(cd "$(dirname "$0")"; pwd)
DST_DIR=$WD/prebuild

LAME_NAME=lame-3.100
LAME_DIR=lame
BUILD_TYPE=Release

build_lame4ndk() {
    tar xvf $LAME_NAME.tar.gz
    pushd $LAME_NAME

    patch -Np0 < mp3lame_ndk.patch

    source $WD/set-ndk-env.sh
    
    mkdir $BUILD_TYPE
    cd $BUILD_TYPE

    if [[ $BUILD_TYPE == "Release" ]]; then
        ../configure --prefix=$DST_DIR/$LAME_DIR \
                --host=aarch64-linux-android23 \
                --disable-debug \
                --with-pic \
                --enable-nasm \
                --enable-shared \
                --enable-static \
                --disable-frontend
    else
        ../configure --prefix=$DST_DIR/$LAME_DIR \
                --host=aarch64-linux-android23 \
                --enable-debug \
                --with-pic \
                --enable-nasm \
                --enable-shared \
                --enable-static \
                --disable-frontend
    fi

    make install
    
    popd
}

set +e

build_lame4ndk
